numAreas = int(input())
dist = [None for _ in range(numAreas)]
for i in range(numAreas):
    dist[i] = list(map(int, input().split()))
cap = list(map(int, input().split()))
[x, p] = map(int, input().split())


def dijkstra(dist, src):
    S = {}
    S[src] = 0
    U = {}
    for i in range(numAreas):
        if i != src:
            U[i] = dist[src][i]
    while len(U):
        minDist = -1
        k = -1
        for i in U:
            if U[i] != -1:
                if U[i] < minDist or minDist == -1:
                    k = i
                    minDist = U[i]
        S[k] = minDist
        U.__delitem__(k)
        for i in U:
            if dist[k][i] != -1:
                tmp = S[k]+dist[k][i]
                if U[i] == -1 or U[i] > tmp:
                    U[i] = tmp
    return S


print(dijkstra(dist, x))
